package logic

import (
	"context"
	"super-mart/models"

	"super-mart/martrpc/internal/svc"
	"super-mart/martrpc/martrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
	return &DetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *DetailLogic) Detail(in *martrpc.DetailRequest) (*martrpc.DetailResponse, error) {
	// todo: add your logic here and delete this line

	var shop models.Shop
	if err := shop.ShopFindById(models.DB, in.ShopId); err != nil {
		return nil, err
	}

	return &martrpc.DetailResponse{
		Name:  shop.Name,
		Num:   int64(shop.Num),
		Price: float32(shop.Price),
	}, nil
}
